package eerbaar.expression.internal.lib;

import eerbaar.area.IArea;
import eerbaar.context.IContext;
import eerbaar.elements.IElement;
import eerbaar.elements.extension.ElementFactory;
import eerbaar.game.IGame;
import eerbaar.position.IPosition;
import eerbaar.position.PositionFactory;

public class PositionGenerator {

    public IPosition createRandom(IContext model) {

        IPosition result = null;

        IGame game = (IGame) model;
        IArea area = game.getArea();
        int y = area.getHeight();
        int x = area.getWidth();
        IPosition max = PositionFactory.createPosition(x, y);

        for (int i = 0; i < 1000; i++) {

            IElement e = ElementFactory.createWithRandomPosition("test", max);
            IPosition p = e.getPosition();
            IElement[] elements = area.getElements(p);
            if (elements.length > 0) {
                continue;
            }

            result = p;
            break;
        }

        return result;
    }
}
